package test.core.data;

import hyl.core.MyDate;
import hyl.core.MyFun;
import hyl.core.data.ExBlockMap;
import hyl.core.data.ExBlockMap2;
import hyl.core.run.MyRun;

public class testblockmap {

	public static void main(String[] dfd) {
		test2_3();
		// test2_1();
		// test2_2() ;
	}

	//测试 get能不能 并发 调用
	// 验证可以并发
	public static void test2_3() {

		ExBlockMap<String, String> ebm = new ExBlockMap<>();
		MyRun.start用户线程(() -> {

			System.out.println(ebm.get("k1"));

		});
		MyRun.start用户线程(() -> {

			System.out.println(ebm.get("k2"));

		});
		MyRun.start用户线程(() -> {

			System.out.println(ebm.get("k3"));
		});
		MyRun.start用户线程(() -> {
			MyFun.print("放k1");
			MyDate.sleep(200);
			ebm.put("k1", "aabb");
		});
		MyRun.start用户线程(() -> {
			MyDate.sleep(200);
			MyFun.print("放k3,2");
			ebm.put("k3", "aadd");
			MyDate.sleeps(2);
			ebm.put("k2", "aacc");
		});
	}

	public static void test2_1() {
		ExBlockMap<String, String> ebm = new ExBlockMap<>();
		MyRun.start用户线程(() -> {
			// MyDate.sleeps(1);
			System.out.println(ebm.get("k1"));
			MyDate.sleeps(1);
			System.out.println(ebm.get("k1"));
			MyDate.sleeps(1);
			System.out.println(ebm.get("k1"));
			// System.out.println(ebm.get("k2"));
		});
		MyRun.start用户线程(() -> {
			ebm.put("k1", "aabb");
			MyDate.sleeps(1);
			ebm.put("k1", "aacc");
			MyDate.sleeps(1);
			ebm.put("k1", "aadd");
			// ebm.put("k2", "aacc");
		});
	}

	public static void test2_2() {
		ExBlockMap2<String, String> ebm = new ExBlockMap2<>();
		MyRun.start用户线程(() -> {
			// MyDate.sleeps(1);
			System.out.println(ebm.get("k1"));
			MyDate.sleeps(1);
			System.out.println(ebm.get("k1"));
			System.out.println(ebm.get("k1"));
			// System.out.println(ebm.get("k2"));
		});
		MyRun.start用户线程(() -> {
			ebm.put("k1", "aabb");
			MyDate.sleeps(1);
			ebm.put("k1", "aacc");
			ebm.put("k1", "aadd");
			// ebm.put("k2", "aacc");
		});
	}

}
